
#include <avr/io.h>
#include "uart.h"
#define NIB_TO_HEX(x) (((x)<10)?((x)+'0'):((x)-10+'A'))

//Init function for the UART.
void uart_init(void){
	/* Set baud rate */
	unsigned int baud = 11;
	UBRR1H = (unsigned char)(baud>>8);
	UBRR1L = (unsigned char)baud;
	/* Enable transmitter */
	UCSR1B |= (1<<RXEN1)|(1<<TXEN1);
	/* Set frame format: 8data, 1stop bit */
	UCSR1C |= (3<<UCSZ10);
}

//Function to send data via the UART.
void uart_send(uint8_t value){
	/* Wait for empty transmit buffer */
	while (!( UCSR1A & (1<<UDRE1))){}
	
	/*Convert int value to char*/
	unsigned char data = (char)(((int)'0')+value);
	
	/* Put data into buffer, sends the data */
	UDR1 = data;
}

void USART_Transmit(unsigned char data){
	/* Wait for empty transmit buffer */
while (!( UCSR1A & (1<<UDRE1))){}

/* Put data into buffer, sends the data */
UDR1 = data;
}

void uart_send_string(char word[]){
	int i,l;
	l = strlen(word);
	for(i=0; i<l; i++){
		USART_Transmit(word[i]);
	}
	//USART_Transmit('\n');
}


